<template>
  <div class="login-wrap">
    <el-form ref="loginRef" :model="form" :rules="rules" class="login">
      <h2 class="login-title">学籍管理系统</h2>
      <el-form-item label="账号" prop="name">
        <el-input
          type="text"
          placeholder="请输入用户名"
          v-model="form.name"
        ></el-input>
        <!-- v-model作用会随你的输入而改变，达到数据双向绑定 -->
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          type="password"
          placeholder="请输入密码"
          v-model="form.password"
        ></el-input>
      </el-form-item>
      <el-form-item>
       <!-- <div class="login-btn">
                    <el-button type="primary" round @click="submit()">登录</el-button> -->
                <!-- </div> -->
      </el-form-item>
       <el-checkbox v-model="checked" class="loginRemember">记住我</el-checkbox>
       <el-button type="primary" style="width: 100%" round @click="submit()">登录</el-button>
    </el-form>
  </div>
</template>

<script >
export default {
  name: 'login',
  data () {
    return {
      form: {
        name: '',
        password: ''
      },
      // 对账户和密码加限制
      rules: {
        name: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    submit () {
      // validata将账户和密码进行验证
      this.$refs.loginRef.validate(async (valid) => {
       if(valid){
          //await只能用在async中
          console.log(this.form);
          this.$message.success("登陆成功");
          this.$router.push('/home')
        }else{
          return
        }
      });
    }
  }
}
</script>

<style>
.login {
  width: 350px;
  margin: 180px auto;
  border: 1px solid #eaeaea;
  padding: 150px 35px 15px;
  border-radius: 15px;
  box-shadow: 0 0 25px #cac6c6;
  /* background-clip: padding-box; */
  background: #fff;
}

.login-title {
  margin: 0px auto 40px auto;
  text-align: center;
}

/* .login-btn {
    text-align: center;
} */

.loginRemember{
      text-align: left;
      margin: 0px 0px 15px 0px;
    }
</style>
